//    Copyright (C) 2013  <lugocreation@gmail.com>
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
package org.jpgolay.me.batch;

import net.sf.jasperreports.engine.*;
import org.jpgolay.me.item.Item;
import org.jpgolay.me.util.Parameter;

// Referenced classes of package org.jpgolay.me.batch:
//            Batch
public class BatchPrintDataSource
        implements JRDataSource {

    public BatchPrintDataSource(Item item, Batch batch, Parameter param) {
        this.item = item;
        this.batch = batch;
        this.param = param;
        count = 6;
    }

    public boolean next()
            throws JRException {
        return count > 0;
    }

    public Object getFieldValue(JRField field)
            throws JRException {
        String fieldname = field.getName();
        String value = null;
        if ("id".equals(fieldname)) {
            value = item.getId().toString();
        } else if ("designation".equals(fieldname)) {
            value = item.getDesignation();
        } else if ("description".equals(fieldname)) {
            value = item.getDescription();
        } else if ("batch".equals(fieldname)) {
            if (batch.getItemBatch() != null) {
                value = "N\260 de lot " + batch.getItemBatch();
            }
        } else if ("dlc".equals(fieldname)) {
            if (batch.getDateDLC() != null) {
                value = "DLC : " + batch.getDateDLC();
            }
        } else if ("dluo".equals(fieldname) && batch.getDateDLUO() != null) {
            value = "DLUO : " + batch.getDateDLUO();
        }
        count--;
        return value;
    }
    private Item item;
    private Batch batch;
    private Parameter param;
    private int count;
}
